package com.fierce.cloud.exception;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.HashMap;
import java.util.Map;

@RestControllerAdvice
@Slf4j
public class GloableExceptionHandler {
    @ResponseBody
    @ExceptionHandler(CustomException.class)
    @ResponseStatus(code = HttpStatus.BAD_REQUEST)
    public Map<String, Object> handleCustomException(CustomException customException) {
        log.debug(customException.getMessage());
        Map<String, Object> errorResultMap = new HashMap<>(16);
        errorResultMap.put("code", customException.getCode());
        errorResultMap.put("message", customException.getMessage());
        return errorResultMap;
    }

//    @ResponseBody
//    @ExceptionHandler(Exception.class)
//    @ResponseStatus(code = HttpStatus.BAD_REQUEST)
//    public Map<String, Object> handleCustomException(Exception e) {
//        log.debug(e.getMessage());
//        Map<String, Object> errorResultMap = new HashMap<>(16);
//        errorResultMap.put("code",400 );
//        errorResultMap.put("message", "参数传递错误，请检查传参类型以及格式是否正确或联系管理员");
//        return errorResultMap;
//    }
}
